#include "widget.h"
#include "ui_widget.h"
#include <QLabel>
#include <QMessageBox>
#include <QApplication>
#include <QFile>
#include <QTextStream>
#include <QTimer>
Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    ui->label_2->setStyleSheet("background-color:#389286;");

    QTimer *timer = new QTimer(this);
    connect(timer,SIGNAL(timeout()),this,SLOT(onUpdate()));
    timer->start(1000);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::onUpdate()
{
    QString strTemp,strHum,strLine;
    double Temp,Hum;
    QFile f("/data/data/org.qtproject.example.sht/files/sht");

    if(f.open(QFile::ReadOnly))
    {
        QTextStream ts(&f);

        strTemp = ts.readLine();
        strLine.append( strTemp);
        strLine.append("\n");

        strHum = ts.readLine();
        strLine.append( strHum);
        ui->label_2->setText(strLine);

        f.close();
    }
    Temp = strTemp.mid(5,4).toDouble();
    ui->progressBar->setValue((int)Temp);

    Hum = strHum.mid(5,4).toDouble();
    ui->progressBar_2->setValue((int)Hum);

}
